package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.learning.domain.dto.QuestionFormDTO;
import com.tianji.learning.domain.dto.QuestionPageQuery;
import com.tianji.learning.domain.vo.QuestionVO;
import com.tianji.learning.service.IInteractionQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 互动提问的问题表 前端控制器
 * </p>
 *
 * @author WFan
 * @since 2025-03-27
 */
@RestController
@Api(tags = "互动提问问题管理")
@RequestMapping("questions")
@RequiredArgsConstructor

public class InteractionQuestionController {

    private final IInteractionQuestionService questionService;

    /**
     * 新增互动问题
     * @param questionDTO
     */
    @PostMapping
    @ApiOperation("保存互动提问问题")
    public void saveQuestion(@ApiParam @RequestBody QuestionFormDTO questionDTO){
        questionService.saveQuestion(questionDTO);
    }

    /**
     * 用户端分页查询互动问题
     * @param pageQuery
     * @return
     */
    @GetMapping("page")
    @ApiOperation("用户端分页查询互动问题")
    public PageDTO<QuestionVO> queryQuestionPage(@ApiParam  QuestionPageQuery pageQuery){
        return questionService.queryQuestionPage(pageQuery);
    }

    /**
     * 编辑互动问题
     * @param questionDTO
     */
    @PutMapping("{id}")
    @ApiOperation("编辑互动问题")
    public void updateQuestion(@RequestBody QuestionFormDTO questionDTO,@PathVariable Long id){
        questionService.updateQuestion(questionDTO, id);
    }

    /**
     * 根据id查询问题详情
     * @param id
     * @return
     */
    @GetMapping("{id}")
    @ApiOperation("根据id查询问题详情")
    public QuestionVO getQuestionById(@PathVariable Long id){
        return questionService.getQuestionById(id);
    }

    /**
     * 根据id删除问题
     * @param id
     */
    @DeleteMapping("{id}")
    public void deleteQuestionById(@PathVariable Long id){
        questionService.removeByIdAndUserId(id);
    }
}
